/**
 * 资源持久模块
 */
define('store/ResourceStore', ['WxCore','restTemplate'], function (wxCore,restTemplate) {

    const module= {
        storeName: 'ResourceStore',
        namespaced: true,
        state: {},
        mutations: {},
        actions: {
            getValidateRule() {
                return {
                    clientId: [
                        { required: true, message: 'clientId不能为空', trigger: 'blur' }
                    ],
                    resourceName: [
                        { required: true, message: '名称不能为空', trigger: 'blur' }
                    ]
                }
            },
            listAll({state, commit}, { clientId }) {
                return restTemplate.request({
                    url: '/api/OauthResource/all',
                    params: {
                        clientId
                    },
                    method: 'get'
                })
            },
            listChild ({ state, commit }, { clientId, parentId }) {
                return restTemplate.request({
                    url: '/api/OauthResource/child',
                    params: { clientId, parentId },
                    method: 'get'
                })
            },
            save({state, commit}, vo) {
                const requestUrl = (vo.resourceId && vo.resourceId !== '') ? '/api/OauthResource/update' : '/api/OauthResource/add';
                return restTemplate.request({
                    url: requestUrl,
                    method: 'post',
                    data: vo
                })
            },
            delete({state, commit},  { clientId, resourceId }) {
                return restTemplate.request({
                    url: 'api/OauthResource/delete',
                    method: 'post',
                    params: {id: resourceId, clientId},
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
            }
        }
    };
    return module;
})